const foo1 = arg => ++arg;
const foo2 = arg => ++arg;
const foo3 = arg => ++arg;

const compose = function(...fns) {
    return fns.reduce(function(prev, cur) {
      return x => prev(cur(x));
    });
};

const xx = compose(foo1, foo2, foo3)(1);
console.log(xx);

// function compose(...funcs) {
//   if (funcs.length === 0) {
//     return arg => arg
//   }
//   if (funcs.length === 1) {
//     return funcs[0]
//   }
//   return funcs.reduce((prev, cur) => {
//     return (...args) => prev(cur(...args))
//   })
//  }
